/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  * @copyright Copyright (c) 2022 SPR
  * All rights reserved.</center></h2>
  *
  * 在此处创建任务
  * osThreadId声明任务句柄
  * osThreadDef定义任务并分配任务优先级，堆栈大小。对涉及复杂数据处理的任务应适当多分配堆栈空间
  * osThreadCreate创建任务，返回句柄
  * 在Task目录下编写对应任务程序
  * 
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */     

#include "aim_task.h"
#include "surgewheel_task.h"
#include "INS_task.h"
#include "odom_serial_task.h"
#include "servo_task.h"
#include "detect_task.h"

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */

//osThreadId chassisTaskHandle;
//osThreadId gimbalTaskHandle;
osThreadId imuTaskHandle;
//osThreadId odom_serialTaskHandle;
osThreadId servoTaskHandle;
osThreadId detectTaskHandle;
//osThreadId agvTaskHandle;

osThreadId testHandle;

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */
osThreadId aim_Task;
osThreadId surgewheel_Task;


/* USER CODE END FunctionPrototypes */

void test_task(void const * argument);

extern void MX_USB_DEVICE_Init(void);
void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/* GetIdleTaskMemory prototype (linked to static allocation support) */
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize );

/* GetTimerTaskMemory prototype (linked to static allocation support) */
void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize );

/* USER CODE BEGIN GET_IDLE_TASK_MEMORY */
static StaticTask_t xIdleTaskTCBBuffer;
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];
  
void vApplicationGetIdleTaskMemory( StaticTask_t **ppxIdleTaskTCBBuffer, StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize )
{
  *ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
  *ppxIdleTaskStackBuffer = &xIdleStack[0];
  *pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
  /* place for user code */
}                   
/* USER CODE END GET_IDLE_TASK_MEMORY */

/* USER CODE BEGIN GET_TIMER_TASK_MEMORY */
static StaticTask_t xTimerTaskTCBBuffer;
static StackType_t xTimerStack[configTIMER_TASK_STACK_DEPTH];
  
void vApplicationGetTimerTaskMemory( StaticTask_t **ppxTimerTaskTCBBuffer, StackType_t **ppxTimerTaskStackBuffer, uint32_t *pulTimerTaskStackSize )  
{
  *ppxTimerTaskTCBBuffer = &xTimerTaskTCBBuffer;
  *ppxTimerTaskStackBuffer = &xTimerStack[0];
  *pulTimerTaskStackSize = configTIMER_TASK_STACK_DEPTH;
  /* place for user code */
}                   
/* USER CODE END GET_TIMER_TASK_MEMORY */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */
       
  /* USER CODE END Init */

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */

  /* Create the thread(s) */
  /* definition and creation of test */
  osThreadDef(test, test_task, osPriorityNormal, 0, 128);
  testHandle = osThreadCreate(osThread(test), NULL);

  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */

//    osThreadDef(chassisTask, chassis_task, osPriorityHigh, 0, 512);
//    chassisTaskHandle = osThreadCreate(osThread(chassisTask), NULL);
	
//    osThreadDef(agvTask, agv_task, osPriorityHigh, 0, 512);
//    agvTaskHandle = osThreadCreate(osThread(agvTask), NULL);
	
//    osThreadDef(gimbalTask, gimbal_task, osPriorityHigh, 0, 512);
//    gimbalTaskHandle = osThreadCreate(osThread(gimbalTask), NULL);

//    osThreadDef(odom_serialTask, odom_serial_task, osPriorityHigh, 0, 256);
//    odom_serialTaskHandle = osThreadCreate(osThread(odom_serialTask), NULL);
		
//    osThreadDef(servoTask, servo_task, osPriorityHigh, 0, 512);
//    servoTaskHandle = osThreadCreate(osThread(servoTask), NULL);
		
	osThreadDef(detectTask, detect_task, osPriorityHigh, 0, 256);
    detectTaskHandle = osThreadCreate(osThread(detectTask), NULL);

   osThreadDef(imuTask, INS_task, osPriorityRealtime, 0, 1024);
   imuTaskHandle = osThreadCreate(osThread(imuTask), NULL);
	
	osThreadDef(aim_Task, aim_task, osPriorityRealtime, 0, 512);
   imuTaskHandle = osThreadCreate(osThread(aim_Task), NULL);
   
   	osThreadDef(surgewheel_Task, surgewheel_task, osPriorityRealtime, 0, 512);
   imuTaskHandle = osThreadCreate(osThread(surgewheel_Task), NULL);
	


  /* USER CODE END RTOS_THREADS */

}

/* USER CODE BEGIN Header_test_task */
/**
  * @brief  Function implementing the test thread.
  * @param  argument: Not used 
  * @retval None
  */
/* USER CODE END Header_test_task */
__weak void test_task(void const * argument)
{
  /* init code for USB_DEVICE */
//  MX_USB_DEVICE_Init();

  /* USER CODE BEGIN test_task */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END test_task */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */
     
/* USER CODE END Application */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
